package StudyCode.summary.myfile;

import java.util.Arrays;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ConvertShortToByteArray {
	public static void main(String[] args) {
		short temp = 8;
		System.out.println("short 型 8 转为字节数组:");
		System.out.println(Arrays.toString(shortToByteArray(temp)));
	}

	private static void shortToByteArray(short value, byte[] array, int offset) {
		array[offset] = (byte) (value >>> 8);
		array[offset + 1] = (byte) value;
	}

	private static byte[] shortToByteArray(short value) {
		final byte[] serverValue = new byte[2];
		shortToByteArray(value, serverValue, 0);
		return serverValue;
	}
}
